define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/index' + location.search,
                    add_url: 'order/add',
                    edit_url: 'order/edit',
                   /* del_url: 'order/del',*/
                    multi_url: 'order/multi',
                    import_url: 'order/import',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_sn', title: __('Order_sn'), operate: 'LIKE'},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'actual_price', title: __('Actual_price'), operate:'BETWEEN'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4'),"5":__('Status 5'),"6":__('Status 6')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'paytype', title: __('Paytype'), searchList: {"1":__('Paytype 1'),"2":__('Paytype 2')}, formatter: Table.api.formatter.status},
                        {field: 'paytime', title: __('Paytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:[
                            {
                                name: 'detail',
                                text: __('发货'),
                                icon: 'fa fa-check',
                                classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                extend: 'style="background-color:#18bc9c"',
                                url: 'order/go_ship',
                                hidden:function(value,row){
                                    if(value.status !=1){
                                        return true; //或者return false
                                    }
                                },
                                /*success: function (data) {
                                    $(".btn-refresh").trigger("click");
                                }*/
                            },{
                                name: 'detail',
                                text: __('查看退款说明'),
                                icon: 'fa fa-close',
                                classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                extend: 'style="background-color:#e74c3c"',
                                url: 'order/refund',
                                hidden:function(value,row){
                                    if(value.status !=4){
                                        return true; //或者return false
                                    }
                                },
                                success: function (data) {
                                    //$(".btn-refresh").trigger("click");
                                }
                            },{
                                name: 'click',
                                text: __('查看快递信息'),
                                icon: 'fa fa-paint-brush',
                                classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                extend: 'style="background-color:#3498db;"',
                                url: 'order/logistics',
                                hidden:function(value,row){
                                    if(value.status <1 || value.courier_code == '' || value.tracking_number == ''){
                                        return true; //或者return false
                                    }
                                },
                            },
                        ]}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        refund: function () {
            $(".sssss input:radio").click(function(){
                if($(this).val() == 6) {
                    $(".none").show();
                } else {
                    $(".none").hide();
                }
            })
            Controller.api.bindevent();
        },
        logistics: function () {
            Controller.api.bindevent();
        },
        go_ship: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});